function defineHeaderToolbar(){
	defineCalculatorWindow();

 	hf.widget.UserInfoField = Ext.extend(Ext.form.TextField, {	
		constructor: function(config) {
			Ext.apply(this, {
            	readOnly: true,
            	style : {fontWeight: 'bold'},
            	flex: 1,
            	width: 150,
            	margins: '0 10 0 5'
        	});
			hf.widget.UserInfoField.superclass.constructor.apply(this, arguments);
		},	
		
		//update user information from server
		update: function() {
			Ext.Ajax.request({
				url: 'auth/info.action',
				success: function(resp, opt){
					var fName = Ext.util.JSON.decode(resp.responseText).data.firstName;
					var lName = Ext.util.JSON.decode(resp.responseText).data.lastName;
					this.setValue(fName+' '+lName);
				},
				failure: function(resp, opt){
					showError(resp);
				},
				scope: this
			});
		}
	});
	Ext.reg('user-info-field', hf.widget.UserInfoField);
    
	hf.widget.EditProfileWindow = Ext.extend(Ext.Window, {
		constructor: function(config) {
			Ext.apply(this, {
				title: labels['edit.profile.title'],
				layout:'fit',
				width:300,
				height:200,
				shadow: new Ext.Shadow({mode: 'drop'}),
				plain: true,
				modal: true,
				draggable: false,
				items: [{
					xtype: 'form',
					itemId: 'editProfileFormId',
					url: 'auth/saveprofile.action',
					frame: true,
					monitorValid: true,
					items: [{
						 xtype: 'form-text-field', 
						 fieldLabel: labels['login.textfield.label'], 
						 name:'j_username', 
						 value: config.loginValue,
						 vtype: 'alphanum',
						 blankText: messages['login.textfield.empty.message'], 
						 vtypeText: messages['login.textfield.invalid.message']
						},
			            {
			             xtype: 'form-text-field', 
			             fieldLabel: labels['password.textfield.label'], 
			             name:'j_password', 
			             value: config.passwordValue,
			       		 inputType: 'password',
			       		 vtype: 'alphanum',
			       		 blankText: messages['password.textfield.empty.message'], 
			       		 vtypeText: messages['password.textfield.invalid.message']
			       		},
			    		{
			    		 xtype: 'form-text-field', 
			    		 fieldLabel: labels['firstname.textfield.label'], 
			    		 name: 'firstName', 
			    		 value: config.firstNameValue,
			         	 vtype: 'alpha',
			         	 blankText: messages['firstname.textfield.empty.message'], 
			         	 vtypeText: messages['firstname.textfield.invalid.message']
			         	},
			     		{
			     	 	 xtype: 'form-text-field', 
			     	 	 fieldLabel: labels['lastname.textfield.label'], 
			     	 	 name: 'lastName', 
			     	 	 value: config.lastNameValue,
			     	 	 vtype: 'alpha',
						 blankText: messages['lastname.textfield.empty.message'],  
						 vtypeText: messages['lastname.textfield.invalid.message']
						}
			       ],
				   buttons:[
				   	 {xtype: 'form-button', 
				   	  text: labels['clear.button.label'], 
				   	  iconCls: 'icon-clear', 
				   	  buttonEvent: 'clear',
				   	  ref: '../../clearButton',
				   	  tooltip: qtips['qtips.button.clear']
				   	 }, 
					 {xtype: 'form-button', 
					  text: labels['button.title.save'], 
					  iconCls: 'icon-save', 
					  buttonEvent: 'saveProfile', 
					  ref: '../../saveButton',
					  formBind: true, 
					  tooltip: qtips['qtips.button.profile.save']
					 }
				   ]	
			    }]
		    });
		    hf.widget.EditProfileWindow.superclass.constructor.apply(this, arguments);
		    
			this.on('saveProfile',function(button, event){
		        this.saveProfile(button, event);	
		    });
		   
		    this.on('clear', function(button, event){
		    	this.clearData(button, event);
		    });
		    
		    this.relayEvents(this.clearButton, ['clear']);
			this.relayEvents(this.saveButton, ['saveProfile']);
		},
		
		//submit form and update user info text field on header toolbar
		saveProfile: function(button, event){
			this.getComponent('editProfileFormId').getForm().submit({
				method:'POST', 
				success:function(form, action){
    				if(Ext.isDefined(this.userInfoField) && this.userInfoField != null){
    					this.userInfoField.update();
    				}
    				form.reset();
    				this.close();
				},
				failure:function(form, action){
					if(action.failureType == Ext.form.Action.SERVER_INVALID){
						obj = Ext.util.JSON.decode(action.response.responseText);
						Ext.Msg.alert(_failureAlertTitle, obj.message);
					}else{
						Ext.Msg.alert(_failureAlertTitle, messages['edit.profile.failure.alert.message']);
					}
				} 
			});
		},
		
		//reset data in form fields
		clearData: function(button, event){
			this.getComponent('editProfileFormId').getForm().reset();
		}
	});
	Ext.reg('edit-profile-window',hf.widget.EditProfileWindow);
	
	hf.widget.HeaderToolBar = Ext.extend(Ext.Toolbar, {
		constructor: function(config) {
			Ext.apply(this, {
				items: [{xtype: 'tbseparator'},
				        {xtype: 'form-button', 
				         text: labels['calculator.title'], 
				         iconCls: 'icon-calculator', 
				         buttonEvent: 'showCalculator', 
				         ref: 'calculatorButton', 
				         tooltip: qtips['qtips.button.calculator']
				        },
				        {xtype: 'tbseparator'},
				        {xtype: 'tbfill'},
				        {xtype: 'tbseparator'},
				        {xtype: 'user-info-field', 
				         ref: 'userInfoField'
				        },
				        {xtype: 'form-button', 
				         text: '', 
				         iconCls: 'icon-edit-profile', 
				         buttonEvent: 'editProfile', 
				         ref: 'editProfileButton', 
				         tooltip: qtips['qtips.button.profile.open']
				        },
				        {xtype: 'tbseparator'},
				        {xtype: 'form-button', 
				         text: labels['button.title.about'], 
				         iconCls: 'icon-about', 
				         buttonEvent: 'showAbout', 
				         ref: 'showAboutButton', 
				         tooltip: qtips['qtips.button.about.application']
				        },
				        {xtype: 'tbseparator'},
				        {xtype: 'form-button', 
				         text: labels['button.logout.label'], 
				         iconCls: 'icon-exit', 
				         buttonEvent: 'logout', 
				         ref: 'logoutButton', 
				         tooltip: qtips['qtips.button.logout']
				        },
				        {xtype: 'tbseparator'}
	        	]	
        	});
			hf.widget.HeaderToolBar.superclass.constructor.apply(this, arguments);
			
			this.on('editProfile', function(button, event){
				this.editProfile(button, event);
			});
			this.on('showAbout', function(button, event){
				this.showAbout(button, event);
			});
			this.on('logout', function(button, event){
			   this.logout(button, event);
			});
			this.on('showCalculator', function(button, event){
				this.showCalculator(button, event);
			});
			
			this.relayEvents(this.editProfileButton, ['editProfile']);
			this.relayEvents(this.showAboutButton, ['showAbout']);
			this.relayEvents(this.logoutButton, ['logout']);
			this.relayEvents(this.calculatorButton, ['showCalculator']);
			this.userInfoField.update();
		},
		
		//show calculator window
		showCalculator: function(button, event){
			new hf.widget.calculatorWindow().show();
		},
		
		//show edit profile window
		editProfile: function(button, event){
			Ext.Ajax.request({
				url: 'auth/info.action',
				success: function(resp, opt){
					var windowConfig = {
						xtype: 'edit-profile-window',
						loginValue: Ext.util.JSON.decode(resp.responseText).data.login,
						passwordValue: Ext.util.JSON.decode(resp.responseText).data.password,
						firstNameValue: Ext.util.JSON.decode(resp.responseText).data.firstName, 
						lastNameValue: Ext.util.JSON.decode(resp.responseText).data.lastName,
						userInfoField: this.userInfoField
					};
					Ext.create(windowConfig).show();
				},
				failure: function(resp, opt){
					showError(resp);
				}
			});
		},
		
		//show window with information about application
		showAbout: function(button, event){
			Ext.Ajax.request({
				url: 'application/info.action',
				success: function(resp, opt){
					var windowConfig = {
						xtype: 'window',
						title: labels['button.title.about'], 
						layout:'fit',
						width:500, 
						height:600,
						shadow: new Ext.Shadow({mode: 'drop'}),
						plain: true, 
						modal: true,
						items: [{xtype: 'textarea', 
								 readOnly: true, 
								 value: Ext.util.JSON.decode(resp.responseText).data}
							   ]};
					Ext.create(windowConfig).show();
				},
				failure: function(resp, opt){
					showError(resp);
				}
			});
		},
		
		//logout user after confirm alert
		logout: function(button, event){
			Ext.Msg.confirm('', messages['logout.confirm.message'], function(btn, text){
	    		if (btn == Ext.MessageBox.buttonText.yes.toLowerCase()){
	    			window.location='j_spring_security_logout';
	    		}
		    });
		}
	});
	Ext.reg('header-toolbar', hf.widget.HeaderToolBar);
};


	
	
